import pymysql as mysql
import pymysql
from pymysql import OperationalError,ProgrammingError,InternalError
import traceback,re
config = {
    'host': '127.0.0.1',
    'port': 3306,
    'user': 'root',
    'passwd': '123456',
    'db': 'taodb',
    'charset': 'utf8'
}
def connect_db():
    try:
        connect = pymysql.connect(**config)
        return connect
    except OperationalError as e:
        # OperationalError 用于捕捉PyMySQL的错误机制，目的是不会出现异常
        print(e)
def row():
    connection=connect_db()
    cursor = connection.cursor()

    # sql_string = "select * from "+str(tabname)
    sql_string = "select * from orderinfo inner join users on users.u_id=orderinfo.o_id"
    # sql_string = "select * , g_price*g_count as total_money from orderinfo inner join goods on orderinfo.og_id=goods.g_id"
    #sql_string = "select u_name,g_name,(g_price*g_count) as all_money from orderinfo,goods,users where orderinfo.o_id=users.u_id and orderinfo.og_id=goods.g_id"
    # sql_string = " select u_name,g_name,(g_price*g_count) as all_money from orderinfo inner join goods on orderinfo.og_id=goods.g_id inner join users on orderinfo.o_id=users.u_id;"
    results_count = cursor.execute(sql_string)
    rows = cursor.fetchall()
    print(rows)
    cursor.close()
    connection.close()
row()




